package com.wnhz.work.jy.fragment;


import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.RelativeSizeSpan;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.animation.LinearInterpolator;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.solidfire.gson.Gson;
import com.wnhz.work.jy.MyApplication;
import com.wnhz.work.jy.MyMain;
import com.wnhz.work.jy.R;
import com.wnhz.work.jy.activity.AssetsActivity;
import com.wnhz.work.jy.activity.GoodDetailsMainActivity;
import com.wnhz.work.jy.activity.LoginActivity;
import com.wnhz.work.jy.activity.PayPasswordActivity;
import com.wnhz.work.jy.activity.SelectGold;
import com.wnhz.work.jy.activity.TrendChartActivity;
import com.wnhz.work.jy.activity.WebActivity;
import com.wnhz.work.jy.adapter.GridViewAdapter;
import com.wnhz.work.jy.adapter.MyViewPagerAdapter;
import com.wnhz.work.jy.bean.HomeFragment1.HomeFragment1Bean;
import com.wnhz.work.jy.bean.HomeFragment1.RecommendBean;
import com.wnhz.work.jy.bean.ManageMoneyBean;
import com.wnhz.work.jy.utils.AddImages;
import com.wnhz.work.jy.utils.ConfigUtil;
import com.wnhz.work.jy.utils.xutils3.MyCallBack;
import com.wnhz.work.jy.utils.xutils3.XUtil;
import com.wnhz.work.jy.view.MarqueeView;
import com.wnhz.work.jy.view.MarqueeView2;
import com.wnhz.work.jy.view.MyScrollView;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 * -----首页
 */
public class HomeFragment1 extends Fragment implements View.OnClickListener {
    private View view;
    private MyScrollView myScroll;
    private ViewPager viewPager;
    private LinearLayout indicatorLayout;
    private TextView tv_number1, tv_number2;
    private String rate1, rate2, rate3;

    private ArrayList<View> viewList = new ArrayList<>();// 添加了首尾的轮播图集合
    private List<String> autoPlayImages = new ArrayList<>();// 轮播图的图片资源集合
    private int currentPosition;
    private ImageView[] indicators;


    private MarqueeView mv_broadcast;//上下滚动
    private MarqueeView2 mv_trend;//上下滚动
    private List<ManageMoneyBean> collect_list = new ArrayList<>();

    /*private RoundProgressBar mRoundProgressBar;//圆形进度条
    private RoundProgressBar roundProgressBar2;//圆形进度条
    private int progress = 0;

    //    private TextView tv_number; //百分号
    private RiseNumberTextView rnTextView;
    private RiseNumberTextView rnTextView2;

    private double code = 40.00;
    private String code1 = "40.00%";*/

    private GridView gridView;//addView
    private LinearLayout linear;
    private GridViewAdapter mAdapter;
    private int screenWidth;
    private List<RecommendBean> homeList = new ArrayList<>();

    private HomeFragment1Bean homeFragment1Bean;

    private RelativeLayout rl_sign;


    /**
     * update ----弹红包
     */
    private View alertParent;
    private ImageView iv_redPackets, iv_redPackets_get, iv_redPackets_close;


    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:

                    break;

                case 2:
                    playImageAnim(image1);
                    currentImage = 1;
                    break;

                default:
                    break;
            }

            super.handleMessage(msg);
        }
    };

    private MyMain myMain;

    private ImageView image1, image2, image3, image4;


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.homefragment1, container, false);
        myMain = (MyMain) getActivity();
        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        initView();
        //1080  576
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        WindowManager wm = (WindowManager) getContext()
                .getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) viewPager.getLayoutParams();
        double d = 576.00 / 1080.00;
        params.height = (int) (width * d);
        viewPager.setLayoutParams(params);

        getData();
    }

    private MarqueeView2.OnItemClickListener marquee_listener = new MarqueeView2.OnItemClickListener() {
        @Override
        public void onItemClick(int position, View v) {
//            myMain.MyToast(position + "");
            if (homeFragment1Bean != null && homeFragment1Bean.getManageMoney() != null
                    && homeFragment1Bean.getManageMoney().get(position) != null)
                startActivity(new Intent(getActivity(), TrendChartActivity.class).putExtra("goodsId",
                        homeFragment1Bean.getManageMoney().get(position).getGoodsId()));
        }
    };

    private void initView() {

        //update--弹红包
        alertParent = view.findViewById(R.id.alert_redPackets);
        iv_redPackets = (ImageView) view.findViewById(R.id.iv_redPackets);
        iv_redPackets_get = (ImageView) view.findViewById(R.id.iv_redPackets_get);
        iv_redPackets_close = (ImageView) view.findViewById(R.id.iv_redPackets_close);

        view.findViewById(R.id.rl_saomiao).setOnClickListener(this);
        image1 = (ImageView) view.findViewById(R.id.iv_maijinbi);
        image2 = (ImageView) view.findViewById(R.id.iv_maijin);
        image3 = (ImageView) view.findViewById(R.id.iv_qujin);
        image4 = (ImageView) view.findViewById(R.id.iv_auction);

        if (null != alertParent) {
            alertParent.setOnTouchListener(new View.OnTouchListener() {
                @Override
                public boolean onTouch(View v, MotionEvent event) {

                    return true;
                }
            });
        }
        iv_redPackets_get.setOnClickListener(this);
        iv_redPackets_close.setOnClickListener(this);

        //update--弹红包--end

        myScroll = (MyScrollView) view.findViewById(R.id.myScroll);
        viewPager = (ViewPager) view.findViewById(R.id.homepager_viewpager);
        indicatorLayout = (LinearLayout) view.findViewById(R.id.homepager_indicator);
        rl_sign = (RelativeLayout) view.findViewById(R.id.rl_sign);

        mv_broadcast = (MarqueeView) view.findViewById(R.id.mv_broadcast);
        mv_trend = (MarqueeView2) view.findViewById(R.id.mv_trend);

       /* rnTextView = (RiseNumberTextView) view.findViewById(R.id.tv_number);
        rnTextView2 = (RiseNumberTextView) view.findViewById(R.id.tv_number2);


        mRoundProgressBar = (RoundProgressBar) view.findViewById(R.id.roundProgressBar);//圆形进度条
        roundProgressBar2 = (RoundProgressBar) view.findViewById(R.id.roundProgressBar2);//圆形进度条*/

        tv_number1 = (TextView) view.findViewById(R.id.tv_number1);
        tv_number2 = (TextView) view.findViewById(R.id.tv_number2);
//        tv_rate3 = (TextView) view.findViewById(R.id.tv_rate3);

        view.findViewById(R.id.rl_collect).setOnClickListener(this);
        view.findViewById(R.id.roundProgressBar).setOnClickListener(this);
        view.findViewById(R.id.view_inform).setOnClickListener(this);
        view.findViewById(R.id.rl_sign).setOnClickListener(this);
        view.findViewById(R.id.rl_buy_gold).setOnClickListener(this);
        view.findViewById(R.id.rl_sell_gold).setOnClickListener(this);
        view.findViewById(R.id.rl_get_gold).setOnClickListener(this);
        view.findViewById(R.id.rl_auction).setOnClickListener(this);

        view.findViewById(R.id.tv_now_buy1).setOnClickListener(this);
        view.findViewById(R.id.tv_now_buy2).setOnClickListener(this);


        playImageAnim(image1);//图片动画
        setViewPager();





       /* // 设置数据
        rnTextView.withNumber((float) code);
        rnTextView2.withNumber((float) code);
        // 设置动画播放时间
        rnTextView.setDuration(1400);
        rnTextView2.setDuration(1400);
        // 监听动画播放结束
        rnTextView.setOnEndListener(new RiseNumberTextView.EndListener() {

            @Override
            public void onEndFinish() {
                Spannable WordtoSpan = new SpannableString(code1);
                WordtoSpan.setSpan(new AbsoluteSizeSpan(24, true), 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                WordtoSpan.setSpan(new AbsoluteSizeSpan(15, true), 2, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                rnTextView.setText(WordtoSpan);
            }
        });

        if (rnTextView.isRunning()) {
        } else {
            // 开始播放动画
            rnTextView.start();
        }

        rnTextView2.setOnEndListener(new RiseNumberTextView.EndListener() {

            @Override
            public void onEndFinish() {
                Spannable WordtoSpan = new SpannableString(code1);
                WordtoSpan.setSpan(new AbsoluteSizeSpan(24, true), 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                WordtoSpan.setSpan(new AbsoluteSizeSpan(15, true), 2, 6, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                rnTextView2.setText(WordtoSpan);
            }
        });

        if (rnTextView2.isRunning()) {
        } else {
            // 开始播放动画
            rnTextView2.start();
        }

        new Thread(new Runnable() {

            @Override
            public void run() {
                while (progress <= code) {
                    progress += 3;
                    mRoundProgressBar.setProgress(progress);
                    roundProgressBar2.setProgress(progress);

                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }

            }
        }).start();*/

        rate1 = " 30%+";
        rate2 = "200%+";
        rate3 = " 40%+";

        tv_number1.setText(getSpannable(rate1));
        tv_number2.setText(getSpannable(rate2));
//        tv_rate3.setText(getSpannable(rate3));

//        rl_sign.setBackgroundResource(R.mipmap.ani_qiandao0001);
        /* rl_sign.setBackgroundResource(R.drawable.shim);
       recordingTransition = (AnimationDrawable) rl_sign.getBackground();//签到动画
        recordingTransition.start();*/


        DisplayMetrics dm = new DisplayMetrics();
        getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm);
        screenWidth = dm.widthPixels;

        linear = (LinearLayout) view.findViewById(R.id.tab1_add_linear);

        addGridView(linear);
        myScroll.setOnTouchListener(new View.OnTouchListener() {
            private int lastY = 0;
            private int touchEventId = -9983761;
            Handler handler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    View scroller = (View) msg.obj;
                    if (msg.what == touchEventId) {
                        if (lastY == scroller.getScrollY()) {
                            handleStop(scroller);
                        } else {
                            handler.sendMessageDelayed(handler.obtainMessage(touchEventId, scroller), 5);
                            lastY = scroller.getScrollY();
                        }
                    }
                }
            };


            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    handler.sendMessageDelayed(handler.obtainMessage(touchEventId, v), 5);
                }
                return false;
            }


            private void handleStop(Object view) {
                ScrollView scroller = (ScrollView) view;
                scrollY = scroller.getScrollY();

            }
        });

//        mv_trend.startWithList();
    }

    int scrollY = 0;
    int currentImage = 1;


    /**
     * 图片翻转动画
     *
     * @param image
     */
    private void playImageAnim(final ImageView image) {
        ObjectAnimator anim1 = ObjectAnimator//
                .ofFloat(image, "alpha", 1.0F, 1.0F);//
        ObjectAnimator anim2 = ObjectAnimator//
                .ofFloat(image, "rotationY", 181, 0);//

        AnimatorSet animSet1 = new AnimatorSet();
        animSet1.setDuration(380);
        animSet1.setInterpolator(new LinearInterpolator());
        // 两个动画同时执行
        animSet1.playTogether(anim1, anim2);
        animSet1.start();

        animSet1.addListener(new Animator.AnimatorListener() {

            @Override
            public void onAnimationStart(Animator animation) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onAnimationRepeat(Animator animation) {
                // TODO Auto-generated method stub
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                switch (currentImage) {
                    case 1:
                        playImageAnim(image2);
                        currentImage = 2;
                        break;

                    case 2:
                        playImageAnim(image3);
                        currentImage = 3;
                        break;

                    case 3:
                        playImageAnim(image4);
                        currentImage = 4;
                        break;

                    case 4:
                        handler.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                mHandler.sendEmptyMessage(2);
                            }
                        }, 7 * 1000);

                        break;
                }
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                // TODO Auto-generated method stub
            }
        });
    }

    /**
     * 改变同一字段字体的大小
     *
     * @param rate
     * @return
     */
    @NonNull
    private Spannable getSpannable(String rate) {
        Spannable WordtoSpan = new SpannableString(rate);
        WordtoSpan.setSpan(new RelativeSizeSpan(1.5f), 0, 4, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return WordtoSpan;
    }

    private void addGridView(LinearLayout linear) {
        View view1 = getActivity().getLayoutInflater().inflate(R.layout.addgridview1, null);
        gridView = (GridView) view1.findViewById(R.id.gridView);

      /*  GridLayoutManager manager = new GridLayoutManager(getActivity(), 2);
        manager.setOrientation(LinearLayoutManager.VERTICAL);*/

        mAdapter = new GridViewAdapter(getActivity(), homeList, screenWidth);
        gridView.setAdapter(mAdapter);

//        mHandler.sendEmptyMessage(1);
        gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(getActivity(), GoodDetailsMainActivity.class);
                intent.putExtra("goodId", homeFragment1Bean.getRecommend().get(position).getGoodId());
                startActivity(intent);
            }
        });
        linear.addView(view1);

    }

    private String id;

    private void initViewPager() {

        int indicatorSize = autoPlayImages.size();

        indicators = new ImageView[indicatorSize];

        for (int i = 0; i < indicators.length; i++) {
            View view = LayoutInflater.from(getActivity()).inflate(R.layout.view_indicator, null);
            indicators[i] = (ImageView) view.findViewById(R.id.image_indicator);
            indicatorLayout.addView(view);
        }

        viewList = AddImages.addImageDatas(getActivity(), autoPlayImages, new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int index = (int) v.getTag();
                String s = homeFragment1Bean.getCarousel().get(index).getJumpType();
                String url = homeFragment1Bean.getCarousel().get(index).getUrl();
                String title = homeFragment1Bean.getCarousel().get(index).getTitle();
                String d = "id/";

                if (url.indexOf(d) > 0) {
                    id = url.substring(url.indexOf(d) + 3, url.length());
                    System.out.println("onSuccess: 1" + id);
                }
                if ("1".equals(s)) {
                    Intent intent = new Intent(getActivity(), GoodDetailsMainActivity.class);
                    intent.putExtra("goodId", id);
                    startActivity(intent);
                } else if ("2".equals(s)) {
                    if (MyApplication.getInstance().userBean != null) {
                        Intent intent = new Intent(getActivity(), WebActivity.class);
                        intent.putExtra("url", url);
                        intent.putExtra("title", title);
                        startActivity(intent);
                    } else {
                        startActivity(new Intent(getActivity(), LoginActivity.class));
                    }
                } else {

                }

            }
        });

        viewPager.setAdapter(new MyViewPagerAdapter(viewList));
        if (indicators.length > 1) {
            viewPager.setCurrentItem(1, false);
        }
    }

    private void setViewPager() {
        viewPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {

            @Override
            public void onPageSelected(int arg0) {
                currentPosition = arg0;
                if (currentPosition < 1) { // 首位之前，跳转到末尾（N）
                    setIndicator(autoPlayImages.size() - 1);
                } else if (currentPosition > autoPlayImages.size()) { // 末位之后，跳转到首位（1）
                    setIndicator(0);
                } else {

                    setIndicator(currentPosition - 1);
                }

            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                if (arg0 == 0) {
                    handler.removeMessages(11);
                    Message message = new Message();
                    message.what = 11;
                    handler.sendMessageDelayed(message, 3000);
                    viewPager.setCurrentItem(currentPosition, false);
                    if (viewList.size() > 1) { // 多于1，才会循环跳转
                        if (currentPosition < 1) { // 首位之前，跳转到末尾（N）
                            currentPosition = autoPlayImages.size(); // 注意这里是mList，而不是mViews
                            viewPager.setCurrentItem(currentPosition, false);
                        } else if (currentPosition > autoPlayImages.size()) { // 末位之后，跳转到首位（1）
                            viewPager.setCurrentItem(currentPosition, true); // false:不显示跳转过程的动画
                            viewPager.setCurrentItem(1, false); // false:不显示跳转过程的动画
                            currentPosition = 1;
                        }

                    }
                }

            }
        });

//        setIndicator(0);
        viewPager.setCurrentItem(1, false);
        handler.removeMessages(11);
        Message message = new Message();
        message.what = 11;
        handler.sendMessageDelayed(message, 3000);
    }


    private Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 11:
                    int position = currentPosition + 1;
                    viewPager.setCurrentItem(position, true);
                    break;

                default:
                    break;
            }
        }

    };

    /**
     * 设置指示器
     *
     * @param selectedPosition 默认指示器位置
     */
    private void setIndicator(int selectedPosition) {


        for (int i = 0; i < indicators.length; i++) {
            indicators[i].setBackgroundResource(R.drawable.icon_point);
        }
        if (indicators.length > selectedPosition)
            indicators[selectedPosition].setBackgroundResource(R.drawable.icon_point_pre);
    }

    @Override
    public void onClick(View v) {
        Intent intent;
        switch (v.getId()) {
            //签到
            case R.id.rl_sign:
                if (MyApplication.getInstance().userBean != null) {
                    intent = new Intent(getActivity(), WebActivity.class);
                    intent.putExtra("url", ConfigUtil.sign + MyApplication.getInstance().userBean.getUserId());
                    intent.putExtra("title", "签到");
                    startActivity(intent);
                } else {
//                    startActivity(new Intent(getActivity(), LoginActivity.class));
                    startActivity(new Intent(getActivity(), LoginActivity.class));
                }
                break;

            /*//通知
            case R.id.view_inform:
                intent = new Intent(getActivity(), InformActivity.class);
                startActivity(intent);
                break;*/

            //买金币
            case R.id.rl_buy_gold:
                myMain.setFragment(3);
                /*intent = new Intent(getActivity(), ProductActivity.class);
                startActivity(intent);*/
                break;

            //卖金币
            case R.id.rl_sell_gold:
                if (MyApplication.getInstance().userBean != null) {
                    startActivity(new Intent(getActivity(), AssetsActivity.class));
                } else {
                    startActivity(new Intent(getActivity(), LoginActivity.class));
                }
                break;

            //提金币
            case R.id.rl_get_gold:
                if (MyApplication.getInstance().userBean != null) {
                    if ("1".equals(MyApplication.getInstance().userBean.getPayPassword())) {
                        startActivity(new Intent(getActivity(), SelectGold.class));//TODO
                    } else {
                        myMain.showDialogv7(R.string.pay_toast, "取消", "去设置", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                startActivity(new Intent(getActivity(), PayPasswordActivity.class));
                            }
                        });
                    }
                } else {
                    startActivity(new Intent(getActivity(), LoginActivity.class));
                }
                break;

            //拍卖
            case R.id.rl_auction:
                Toast.makeText(getActivity(), "模块开发中，敬请期待~", Toast.LENGTH_SHORT).show();
                break;

            //收藏--立即购买
            case R.id.tv_now_buy1:
                break;

            //投资--立即购买
            case R.id.tv_now_buy2:
                myMain.MyToast("模块开发中");
                break;

            //精选商品---更多
            case R.id.rl_collect:
                myMain.setFragment(3);
                /*intent = new Intent(getActivity(), ProductActivity.class);
                startActivity(intent);*/
                break;

            //领取红包
            case R.id.iv_redPackets_get:
                if (MyApplication.getInstance().userBean != null) {
                    Toast.makeText(getActivity(), "领取红包", Toast.LENGTH_SHORT).show();
                    alertParent.setVisibility(View.GONE);
                } else {
                    startActivity(new Intent(getActivity(), LoginActivity.class));
                }
                break;

            //关闭红包弹窗
            case R.id.iv_redPackets_close:
                Toast.makeText(getActivity(), "关闭红包", Toast.LENGTH_SHORT).show();

                alertParent.setVisibility(View.GONE);
                break;
            case R.id.rl_saomiao://扫一扫
                if (MyApplication.getInstance().userBean != null) {
                    myMain.scanCode();
                } else {
                    startActivity(new Intent(getActivity(), LoginActivity.class));
                }

                break;
            default:
                break;
        }
    }


    public void onResume() {
        setscrollY();
        super.onResume();


    }

    public void setscrollY() {
        myScroll.scrollTo(0, scrollY);
        myScroll.smoothScrollTo(0, scrollY);
    }

    private static final String TAG = "HomeFragment1";

    private void getData() {
        myMain.showProgress("加载中");
        XUtil.Get(ConfigUtil.HOME, new MyCallBack<String>() {
            @Override
            public void onSuccess(String result) {
                super.onSuccess(result);
                Log.e(TAG, "onSuccess: 1" + result);
                homeFragment1Bean = new HomeFragment1Bean();
                Gson gson = new Gson();
                homeFragment1Bean = gson.fromJson(result, HomeFragment1Bean.class);
                System.out.println("ConfigUtil  " + homeFragment1Bean.toString());
                homeList.clear();
                homeList.addAll(homeFragment1Bean.getRecommend());
                mAdapter.notifyDataSetChanged();
                autoPlayImages.clear();
                for (int i = 0; i < homeFragment1Bean.getCarousel().size(); i++) {
                    autoPlayImages.add(homeFragment1Bean.getCarousel().get(i).getImg());
                }
                if (homeFragment1Bean.getInformation() != null) {
                    if (homeFragment1Bean.getInformation().size() > 0) {
                        mv_broadcast.startWithList(homeFragment1Bean.getInformation());
                    }
                }


                if (homeFragment1Bean.getManageMoney() != null) {
                    collect_list.clear();
                    collect_list.addAll(homeFragment1Bean.getManageMoney());
                    mv_trend.startWithList(collect_list);
                    mv_trend.setOnItemClickListener(marquee_listener);
                }

                initViewPager();

                //myScroll.smoothScrollTo(0, 0);
                myScroll.scrollTo(0, 0);
            }

            @Override
            public void onFinished() {
                myMain.hideProgress();
                super.onFinished();
            }
        });

    }


}
